/**************************************************************************
 *         Copyright(c) 2007 by Sunplus mMedia  Technology Co., Ltd.       *
 *                                                                         *
 *  This software is copyrighted by and is the property of Sunplus mMedia  *
 *  Technology Co., Ltd. All rights are reserved by Sunplus mMedia Techno- *
 *  logy Co., Ltd. This software may only be used in accordance with the   *
 *  corresponding license agreement. Any unauthorized use, duplication,    *
 *  distribution, or disclosure of this software is expressly forbidden.   *
 *                                                                         *
 *  This Copyright notice "M U S T" not be removed or modified without     *
 *  prior written consent of Sunplus mMedia Technology  Co., Ltd.          *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd. reserves the right to modify this  *
 *  software without notice.                                               *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd.                                    *
 *  19-1, Innovation First Road, Science-Based Industrial Park,            *
 *  Hsin-Chu, Taiwan, R.O.C.                                               *
 *                                                                         *
 **************************************************************************/
#include "general.h"
#include "os_msg.h"

#include "sp1k_pb_api.h"

#include "app_menu.h"
#include "app_menu_api.h"
#include "app_menu_core.h"
#include "app_ui_para.h"
#include "app_main.h"
#include "app_still_play.h"
#include "app_ui_power.h"//jintao.liu 2008-4-7 add for copy_to_card
#include "app_menu_micro.h"

/**************************************************************************
 *                           C O N S T A N T S                            *
 **************************************************************************/
 
/**************************************************************************
 *                              M A C R O S                               *
 **************************************************************************/

/**************************************************************************
 *                          D A T A    T Y P E S                          *
 **************************************************************************/

/**************************************************************************
 *                         G L O B A L    D A T A                         *
 **************************************************************************/
 
/**************************************************************************
 *				   E X T E R N A L	  R E F E R E N C E S				  *
 **************************************************************************/
extern SIMAGE xdata pbFile;
extern UINT8 xdata G_SDCardPlug;

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuSIDCIsActive (void) USING_0
{
	return FALSE;//By phil for demo
}

/* ------ Note: Demo code zone start flag, don't modify or delete this line!!! ------ */
/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuPhotoFrameIsActive(void) USING_0
{
	if(appPreStateGet(0)==APP_STATE_STILL_VIEW)
	{
		return TRUE;
	}
 	if (pbFile.bFileErr == TRUE)
		return FALSE;

	if (sp1kPbFileCntGet())
	{
		appPbFileInfoUpdate();
		//add for mantis #37356,#37270@start
		if(appPreStateGet(0) ==APP_STATE_MUTI_PLAY)
		{
			return FALSE;
		}
		if(sp1kpbDecRotModeGet() != 0)
		{
			return FALSE;
		}
		//add for mantis #37356,#37270@end
		if (pbFile.wType == SP1K_PB_FILE_TYPE_JPG)
			return TRUE;
	}

	return FALSE;

}
/* ------ Note: Demo code zone end flag, don't modify or delete this line!!! ------ */		

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuProtectIsActive (void) USING_0
{
	if ( APP_STATE_MUTI_PLAY == appPreStateGet(0))
		return FALSE;//mantis #27903
	
	if (pbFile.bFileErr == TRUE)
		return FALSE;//2008-7-28 mantis #28190

	if (sp1kPbFileCntGet())
	{
		return TRUE;
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuDeleteIsActive (void) USING_0
{
	if (sp1kPbFileCntGet())
	{
		return TRUE;
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuSlideStartIsActive (void) USING_0
{
	if (pbFile.bFileErr == TRUE)
		return FALSE;//2008-7-28 mantis #28190
	
	if (sp1kPbFileCntGet())
	{
		if (pbFile.wType == SP1K_PB_FILE_TYPE_JPG)
			return TRUE;
	}

	return FALSE;
}
/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuSlideShowIsActive(void) USING_0
{
	if (pbFile.bFileErr == TRUE)
		return FALSE;//2008-7-28 mantis #28190

	if (sp1kPbFileCntGet())
	{
		appPbFileInfoUpdate();//2008-7-9 mantis #27986
		
		if (pbFile.wType == SP1K_PB_FILE_TYPE_JPG)
			return TRUE;
	}

	return FALSE;
}
#if 0
/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuCopyToCardIsActive (void) USING_0
{
	return FALSE;
	if (sp1kPbFileCntGet())
	{
		if (appSDPlugStatusGet() == 1)
		{
			return TRUE;
		}
	}

}
#endif
/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuEffectIsActive (void) USING_0
{
	if ( APP_STATE_MUTI_PLAY == appPreStateGet(0))
		return FALSE;

	if (pbFile.bFileErr == TRUE)
		return FALSE;//2008-7-28 mantis #28190
	
	if (sp1kPbFileCntGet())
	{
		if (pbFile.wType == SP1K_PB_FILE_TYPE_JPG)
			return TRUE;
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuRotateIsActive (void) USING_0
{
	if ( APP_STATE_MUTI_PLAY == appPreStateGet(0))
		return FALSE;

	if (pbFile.bFileErr == TRUE)
		return FALSE;//2008-7-28 mantis #28190
	
	if (sp1kPbFileCntGet())
	{
		if (pbFile.wType == SP1K_PB_FILE_TYPE_JPG)
			return TRUE;
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuRisizeIsActive (void) USING_0
{
	if ( APP_STATE_MUTI_PLAY == appPreStateGet(0))
		return FALSE;

	if (pbFile.bFileErr == TRUE)
		return FALSE;//2008-7-28 mantis #28190
	
	if (sp1kPbFileCntGet())
	{
		if (pbFile.wType == SP1K_PB_FILE_TYPE_JPG) {
			return TRUE;
		}
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuRisize3MIsActive (void) USING_0
{
	PBFile_t pFileInfo;

	if (sp1kPbFileCntGet())
	{
		//return TRUE;
		sp1kPbFileInfoGet(sp1kPbFileIndexByOrderGet(pbFile.dwIndex), &pFileInfo);
		if (pFileInfo.FileType == SP1K_PB_FILE_TYPE_JPG)
		{	 //printf("w=%ld\n", (long)pFileInfo.MediaWidth);  printf("h=%ld\n", (long)pFileInfo.MediaHeight);
			if ((pFileInfo.MediaWidth > 2048) && (pFileInfo.MediaHeight > 1536))
			{
				return TRUE;
			}
		}
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuRisize1MIsActive (void) USING_0
{
	PBFile_t pFileInfo;

	if (sp1kPbFileCntGet())
	{
		//return TRUE;
		sp1kPbFileInfoGet(sp1kPbFileIndexByOrderGet(pbFile.dwIndex), &pFileInfo);
		if (pFileInfo.FileType == SP1K_PB_FILE_TYPE_JPG)
		{
			if ((pFileInfo.MediaWidth > 1024) && (pFileInfo.MediaHeight > 768))
			{
				return TRUE;
			}
		}
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuRisizeVGAIsActive (void) USING_0
{
	PBFile_t pFileInfo;

	if (sp1kPbFileCntGet())
	{
		//return TRUE;
		sp1kPbFileInfoGet(sp1kPbFileIndexByOrderGet(pbFile.dwIndex), &pFileInfo);
		if (pFileInfo.FileType == SP1K_PB_FILE_TYPE_JPG)
		{
			if ((pFileInfo.MediaWidth > 640) && (pFileInfo.MediaHeight > 480))
			{
				return TRUE;
			}
		}
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuVoiceMemoIsActive (void) USING_0
{
	if ( APP_STATE_MUTI_PLAY == appPreStateGet(0))
		return FALSE;

	if (pbFile.bFileErr == TRUE)
		return FALSE;//2008-7-28 mantis #28190
	
	if (sp1kPbFileCntGet())
	{
		if (pbFile.wType == SP1K_PB_FILE_TYPE_JPG)
			return TRUE;
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuStartupIsActive (void) USING_0
{
	if ( APP_STATE_MUTI_PLAY == appPreStateGet(0))
		return FALSE;

	if (pbFile.bFileErr == TRUE)
		return FALSE;//2008-7-28 mantis #28190
	
	if (sp1kPbFileCntGet())
	{
		if (pbFile.wType == SP1K_PB_FILE_TYPE_JPG)
			return TRUE;
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuMyImageIsActive (void) USING_0
{
	uiPara_t* puiPara = appUiParaGet();
	
	if (puiPara->OpenPic == PB_OPENPIC_USER_DEF)
	{
		return TRUE;
	}

	return FALSE;
}
/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/

UINT8 menuVoiceMemoAddIsActive (void) USING_0
{

	if (sp1kPbFileCntGet())
	{
		if(pbFile.wType == SP1K_PB_FILE_TYPE_JPG)
			return TRUE;
	}

	return FALSE;
}
/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/

UINT8 menuVoiceMemoDeleteIsActive (void) USING_0
{

	if (sp1kPbFileCntGet())
	{
		if(pbFile.wType == SP1K_PB_FILE_TYPE_JPG && pbFile.bVoiceMemo == TRUE)
			return TRUE;
	}

	return FALSE;
}
#if 0
/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuSpanishIsActive (void) USING_0
{
	if (0)
	{
		return TRUE;
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuGermanIsActive (void) USING_0
{
	if (0)
	{
		return TRUE;
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuFrenchIsActive (void) USING_0
{
	if (0)
	{
		return TRUE;
	}

	return FALSE;
}

/**************************************************************************
 *                                                                        *
 *  Function Name:                                                        *
 *                                                                        *
 *  Purposes:                                                             *
 *                                                                        *
 *  Descriptions:                                                         *
 *                                                                        *
 *  Arguments:                                                            *
 *                                                                        *
 *  Returns: None                                                         *
 *                                                                        *
 *  See also:                                                             *
 *                                                                        *
 **************************************************************************/
UINT8 menuItalianIsActive (void) USING_0
{
	if (0)
	{
		return TRUE;
	}

	return FALSE;
}
#endif


